<?php
/**
 * 基础Model类，所有的Model文件均继承本类
 * User: lisgroup
 * Time: 2017/5/21 16:07
 */
namespace lisfw\DB;

class Model implements DbInterface {
    
    protected $dbConfigKey = null;
    
    private $_db = null;

    private function _getInstance()
    {
        if (is_null($this->_db)) {
            if (is_null($this->dbConfigKey)) {
                $this->_db = DB::factor();
            }else {
                $this->_db = DB::factor($this->dbConfigKey);
            }
        }
        return $this->_db;
    }

    //查询方法
    public function query($sql)
    {
        return $this->_getInstance()->query($sql);
    }
    //查询二维数组
    public function getAll($sql)
    {
        return $this->_getInstance()->getAll($sql);
    }
    //单个值
    public function getOne($sql)
    {
        return $this->_getInstance()->getOne($sql);
    }
    //一行
    public function getCol($sql)
    {
        return $this->_getInstance()->getCol($sql);
    }
    //一列
    public function getRow($sql)
    {
        return $this->_getInstance()->getRow($sql);
    }
    //关闭
    public function close()
    {
        $this->_getInstance()->close();
    }
}